//
//  UIViewController+Share.m
//  HiMaster3
//
//  Created by jinghao on 15/12/21.
//  Copyright © 2015年 jinghao. All rights reserved.
//

#import "UIViewController+Share.h"

@implementation UIViewController (Share)
- (void)shareContentOfApp:(NSString*)title content:(NSString*)content imageUrl:(NSString*)imageUrl with:(NSUInteger)snsType{
    
    [self shareContentOfApp:title content:content imageUrl:imageUrl linkUrl:nil with:snsType];
   
}

- (void)shareContentOfApp:(NSString*)title content:(NSString*)content imageUrl:(NSString*)imageUrl linkUrl:(NSString*)linkUrl with:(NSUInteger)snsType {
    
    if (linkUrl==nil || ![linkUrl isKindOfClass:[NSString class]] || linkUrl.length==0) {
        linkUrl = WEB_DOMAIN;
    }
    
    //qq分享内容封装
    [UMSocialData defaultData].extConfig.qqData.title = title;
    [UMSocialData defaultData].extConfig.qqData.url = linkUrl;
    [UMSocialData defaultData].extConfig.qqData.qqMessageType = UMSocialQQMessageTypeDefault;
    [UMSocialData defaultData].extConfig.qqData.shareText = content;
   
    
    //微信好友分享的封装
    [UMSocialData defaultData].extConfig.wechatSessionData.title = title;
    [UMSocialData defaultData].extConfig.wechatSessionData.url = linkUrl;
    [UMSocialData defaultData].extConfig.wechatSessionData.wxMessageType = UMSocialWXMessageTypeWeb;
    [UMSocialData defaultData].extConfig.wechatSessionData.shareText = content;

    //微信朋友圈分享的封装
    [UMSocialData defaultData].extConfig.wechatTimelineData.title = content;
    [UMSocialData defaultData].extConfig.wechatTimelineData.url = linkUrl;
    [UMSocialData defaultData].extConfig.wechatTimelineData.wxMessageType = UMSocialWXMessageTypeWeb;
    [UMSocialData defaultData].extConfig.wechatTimelineData.shareText = content;

    //新浪微博分享
    [UMSocialData defaultData].extConfig.sinaData.shareText = content;
    
    imageUrl = [imageUrl masterFullImageUrl];
    
//    [UMSocialSnsService presentSnsIconSheetView:self
//                                         appKey:UMENG_APPKEY
//                                      shareText:content
//                                     shareImage:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]
//                                shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToQQ]
//                                       delegate:self];
    if(snsType ==1){
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatSession] content:content image:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
    }else if(snsType ==2){
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToQQ] content:content image:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
    }else if (snsType ==3){
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToWechatTimeline] content:content image:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];
    }else{
        [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[UMShareToSina] content:content image:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]] location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response){
            if (response.responseCode == UMSResponseCodeSuccess) {
                NSLog(@"分享成功！");
            }
        }];

    }
}

- (void)shareContentOfApp:(NSMutableDictionary*)shareInfo
{
    NSLog(@"shareInfo  %@",shareInfo);
    [self shareContentOfApp:shareInfo[@"title"] content:shareInfo[@"desc"] imageUrl:shareInfo[@"imgUrl"] linkUrl:shareInfo[@"link"] with:[shareInfo[@"snsType"] integerValue]];
}





@end
